<?php

namespace App\Http\Controllers\Backend;


use App\Models\Admin;
use App\Models\SiteGold;

class SiteGoldController extends BaseController
{
    // 话题
    public function initialize()
    {
        parent::initialize();

        $this->model = 'SiteGold';
    }

    // 父级
    // 添加，修改，删除，列表，停用 操作


    // 添加
    protected function _before_add()
    {
        $data = [
            'title' => $this->getData('title', null, 'trim'),
            'field' => $this->getData('field', null, 'trim'),
            'itype' => $this->getData('itype', null, 'trim'),
            'price' => $this->getData('price', 0, 'intval'),
            'times' => $this->getData('times', 0, 'intval'),
        ];

        // 检查唯一性
        $model = new SiteGold();
        $data  = $model->checkGold($data, $this->id);
        $this->throwIf($data === false, $model->getError());

        return $data;
    }

    // 修改
    protected function _before_edit()
    {
        $data = [
            'title' => $this->getData('title', null, 'trim'),
            'field' => $this->getData('field', null, 'trim'),
            'itype' => $this->getData('itype', null, 'trim'),
            'price' => $this->getData('price', 0, 'intval'),
            'times' => $this->getData('times', 0, 'intval'),
        ];

        // 检查唯一性
        $model = new SiteGold();
        $data  = $model->checkGold($data, $this->id);
        $this->throwIf($data === false, $model->getError());

        return $data;
    }

}


